package com.karry.yl.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.karry.commons.base.SuperController;
import com.karry.commons.util.TimeUtil;
import com.karry.commons.vo.JsonResponse;
import com.karry.yl.domain.baseinfo.Bed;
import com.karry.yl.domain.baseinfo.Organization;
import com.karry.yl.domain.elder.CheckInRecords;
import com.karry.yl.domain.elder.CheckOutRecords;
import com.karry.yl.domain.elder.Elderly;
import com.karry.yl.domain.mz.MzDepartment;
import com.karry.yl.domain.system.Advice;
import com.karry.yl.service.baseinfo.BedService;
import com.karry.yl.service.baseinfo.OrganizationService;
import com.karry.yl.service.elder.CheckInRecordsService;
import com.karry.yl.service.elder.CheckOutRecordsService;
import com.karry.yl.service.elder.ElderlyService;
import com.karry.yl.service.mz.MzDepartmentService;
import com.karry.yl.service.system.AdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class MainController extends SuperController {

    @Autowired
    private ElderlyService elderlyService;
    @Autowired
    private CheckInRecordsService checkInRecordsService;
    @Autowired
    private CheckOutRecordsService checkOutRecordsService;
    @Autowired
    private BedService bedService;
    @Autowired
    private OrganizationService organizationService;
    @Autowired
    private AdviceService adviceService;

    @Autowired
    private MzDepartmentService mzDepartmentService;

    /**
     * 跳转到主页面
     *
     * @return
     */
    @RequestMapping("/")
    public String mainUI(ModelMap map, HttpSession session) {
        Organization organization = organizationService.selectById(currentUser.getOrgId());
        session.setAttribute("organization", organization);
        return "main";
    }

    /**
     * 主页弹窗页面,查看机构是否备案
     *
     * @return string
     */
    @RequestMapping("/judge")
    @ResponseBody
    public JsonResponse judge() {
        //查看当前登陆的机构
        Organization organization = organizationService.selectById(currentUser.getOrgId());
        Integer filingStart = organization.getFilingStart();
        //防止先前注册用户没有添加备案状态
        if (filingStart == null) {
            organization.setFilingStart(0);
        }
        if (organization.getFilingStart() == 0) {
            return new JsonResponse(0, "未备案");
        }
        return new JsonResponse(200, "已提交备案信息");
    }


    /**
     * 没有备案弹框
     * @return
     */
    @RequestMapping("/show")
    public String show(ModelMap map) {
        Organization organization = organizationService.selectById(currentUser.getOrgId());
        map.put("org",organization);
        return "verification";
    }
}
